package com.fuful.servlet;

import com.fuful.domain.Cart;
import com.fuful.domain.Users;
import com.fuful.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class MyCartAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Users myUser = (Users)session.getAttribute("user");
        //调用业务逻辑
        CartService cs = new CartService();
        List<Cart> carts = cs.getMyCart(myUser);
        //共享对象
        session.setAttribute("mycarts",carts);
        //重定向
        response.sendRedirect("mycart.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

